﻿using System;
using System.Collections.Generic;
using System.Text;

namespace StockTrader.BusinessService.DataContract.HnxInfo
{
    public class HnxOrdersData
    {
        #region [Variables]
        public decimal OrderId { get; set; }
        public decimal OrgOrderId { set; get; }
        public string FloorCode { set; get; }
        public string OrderConfirmNo { set; get; }

        public string OrderNo { get; set; }
        public string CoOrderNo { set; get; }
        public string OrgOrderNo { set; get; }

        public DateTime OrderDate { get; set; }
        public string OrderTime { get; set; }
        public int MemberId { get; set; }
        public int StockId { get; set; }
        public string OrderType { get; set; }
        public string OrderSide { get; set; } //oorb
        public string OrderClass { get; set; } //norp
        public string ModifiedStatus { get; set; } //norc
        public int Settlement { get; set; }
        public string InvestorType { get; set; } //dorf
        public decimal OrderPrice { get; set; }
        public decimal OrderQtty { get; set; }
        public string Status { get; set; }
        public decimal QuotePrice { get; set; }
        public decimal QuoteQtty { get; set; }
        public decimal ExecQtty { get; set; }
        public decimal CorrectQtty { get; set; }
        public decimal CancelQtty { get; set; }
        public string AccountNo { get; set; }
        public string CoAccountNo { get; set; }
        public int BrokerId { get; set; }
        public long TimeStamp { get; set; }

        #endregion

        public HnxOrdersData()
        {

        }
        public HnxOrdersData(decimal orderid, decimal orgOrderId, string floorCode, string orderConfirmNo, string orderno, string coOrderNo, string orgOrderNo, DateTime orderdate, string time, decimal memberid, decimal stockid, decimal ordertype, decimal norb, decimal norp, decimal norc, decimal setttype, decimal dorf, decimal orderqtty, decimal orderprice, decimal status, decimal quoteprice, decimal quoteqtty, decimal execqtty, decimal correcqtty, decimal cancelqtty, string accno, string coaccountno, decimal brokerid)
        {
            this.OrderId = orderid;
            this.OrgOrderId = orgOrderId;
            this.FloorCode = floorCode;
            this.OrderConfirmNo = orderConfirmNo;
            this.OrderNo = orderno;
            this.CoOrderNo = coOrderNo;
            this.OrgOrderNo = orgOrderNo;
            this.OrderDate = orderdate;
            this.OrderTime = time;
            this.MemberId = Convert.ToInt32(memberid);
            this.StockId = Convert.ToInt32(stockid);
            switch (Convert.ToInt32(ordertype))
            {
                case 0:
                    this.OrderType = "Limit";
                    break;
                case 1:
                    this.OrderType = "Market";
                    break;
                case 2:
                    this.OrderType = "ATO";
                    break;
                default:
                    this.OrderType = "None";
                    break;
            }

            this.OrderSide = (norb.Equals(1)) ? "Buy" : "Sell";
            this.OrderClass = (norp.Equals(1)) ? "Normal" : "Negotiate";

            switch (Convert.ToInt32(norc))
            {
                case 2:
                    this.ModifiedStatus = "NORMAL";
                    break;
                case 3:
                    this.ModifiedStatus = "CHANGE";
                    break;
                case 5:
                    this.ModifiedStatus = "MATCH";
                    break;
                case 6:
                    this.ModifiedStatus = "Wait";
                    break;
                case 7:
                    this.ModifiedStatus = "Modified";
                    break;
                case 4:
                    this.ModifiedStatus = "CANCEL";
                    break;
                case 9:
                    this.ModifiedStatus = "Matched";
                    break;
                case 10:
                    this.ModifiedStatus = "Quote";
                    break;
                case 11:
                    this.ModifiedStatus = "Deal";
                    break;
                default:
                    this.ModifiedStatus = "Unknown";
                    break;
            }
            this.Settlement = Convert.ToInt32(setttype);
            this.InvestorType = (dorf.Equals(1)) ? "Domestic" : "Foreign";
            this.OrderQtty = orderqtty;
            this.OrderPrice = orderprice;
            this.Status = status.Equals(1) ? "Normal" : "Unknown";
            this.QuotePrice = quoteprice;
            this.QuoteQtty = quoteqtty;
            this.AccountNo = accno;
            this.CoAccountNo = coaccountno;
            this.BrokerId = Convert.ToInt32(brokerid);
            this.ExecQtty = execqtty;
            this.CorrectQtty = correcqtty;
            this.CancelQtty = cancelqtty;
            this.TimeStamp = DateTime.Now.Ticks;
        }

        public HnxOrdersData(decimal OrderId, string OrderNo, DateTime OrderDate, string OrderTime, int MemberId, int StockId, string OrderType, string OrderSide, string OrderClass, string ModifiedStatus, int Settlement, string InvestorType, decimal OrderPrice, decimal OrderQtty, string Status, decimal QuotePrice, decimal QuoteQtty, decimal ExecQtty, decimal CorrectQtty, decimal CancelQtty, string AccountNo, string CoAccountNo, decimal BrokerId, long TimeStamp)
        {
            this.OrderId = OrderId;
            this.OrderNo = OrderNo;
            this.OrderDate = OrderDate;
            this.OrderTime = OrderTime;
            this.MemberId = MemberId;
            this.StockId = StockId;
            this.OrderType = OrderType;
            this.OrderSide = OrderSide;
            this.OrderClass = OrderClass;
            this.ModifiedStatus = ModifiedStatus;
            this.Settlement = Settlement;
            this.InvestorType = InvestorType;
            this.OrderPrice = OrderPrice;
            this.OrderQtty = OrderQtty;
            this.Status = Status;
            this.QuotePrice = QuotePrice;
            this.QuoteQtty = QuoteQtty;
            this.ExecQtty = ExecQtty;
            this.CorrectQtty = CorrectQtty;
            this.CancelQtty = CancelQtty;
            this.AccountNo = AccountNo;
            this.CoAccountNo = CoAccountNo;
            this.BrokerId = Convert.ToInt32(BrokerId);
            this.TimeStamp = TimeStamp;
        }

        public HnxOrdersData(decimal OrderId, decimal orgOrderId, string floorCode, string orderConfirmNo, string OrderNo, string coOrderNo, string orgOrderNo, DateTime OrderDate, string OrderTime, int MemberId, int StockId, string OrderType, string OrderSide, string OrderClass, string ModifiedStatus, int Settlement, string InvestorType, decimal OrderPrice, decimal OrderQtty, string Status, decimal QuotePrice, decimal QuoteQtty, decimal ExecQtty, decimal CorrectQtty, decimal CancelQtty, string AccountNo, string CoAccountNo, decimal BrokerId)
        {
            this.OrderId = OrderId;
            this.OrgOrderId = orgOrderId;
            this.FloorCode = floorCode;
            this.OrderConfirmNo = orderConfirmNo;
            this.OrderNo = OrderNo;
            this.CoOrderNo = coOrderNo;
            this.OrgOrderNo = orgOrderNo;
            this.OrderDate = OrderDate;
            this.OrderTime = OrderTime;
            this.MemberId = MemberId;
            this.StockId = StockId;
            this.OrderType = OrderType;
            this.OrderSide = OrderSide;
            this.OrderClass = OrderClass;
            this.ModifiedStatus = ModifiedStatus;
            this.Settlement = Settlement;
            this.InvestorType = InvestorType;
            this.OrderPrice = OrderPrice;
            this.OrderQtty = OrderQtty;
            this.Status = Status;
            this.QuotePrice = QuotePrice;
            this.QuoteQtty = QuoteQtty;
            this.ExecQtty = ExecQtty;
            this.CorrectQtty = CorrectQtty;
            this.CancelQtty = CancelQtty;
            this.AccountNo = AccountNo;
            this.CoAccountNo = CoAccountNo;
            this.BrokerId = Convert.ToInt32(BrokerId);
        }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            if ((OrderId - ((HnxOrdersData)obj).OrderId).Equals(0))
            {
                if (OrderTime.Equals(((HnxOrdersData)obj).OrderTime))
                    return this.QuotePrice.CompareTo(((HnxOrdersData)obj).QuotePrice);
                else
                    return OrderTime.CompareTo(((HnxOrdersData)obj).OrderTime);
            }
            else
                return OrderId.CompareTo(((HnxOrdersData)obj).OrderId);
        }

        public override bool Equals(object obj)
        {
            if (OrderId.Equals(((HnxOrdersData)obj).OrderId))
            {
                if (OrderTime.Equals(((HnxOrdersData)obj).OrderTime))
                    return this.QuotePrice.Equals(((HnxOrdersData)obj).QuotePrice);
                else
                    return OrderTime.Equals(((HnxOrdersData)obj).OrderTime);
            }
            else
                return OrderId.Equals(((HnxOrdersData)obj).OrderId);
        }
        #endregion

    }
}
